<?php
/**
 *                          _ooOoo_
 *                         o8888888o
 *                         88" . "88
 *                         (| -_- |)
 *                         O\  =  /O
 *                      ____/`---'\____
 *                    .'  \|     |//  `.
 *                   /  \|||  :  |||//  \
 *                  /  _||||| -:- |||||-  \
 *                  |   | \\  -  /// |   |
 *                  | \_|  ''\---/''  |   |
 *                  \  .-\__  `-`  ___/-. /
 *                ___`. .'  /--.--\  `. . __
 *             ."" '<  `.___\_<|>_/___.'  >'"".
 *            | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *            \  \ `-.   \_ __\ /__ _/   .-` /  /
 *       ======`-.____`-.___\_____/___.-`____.-'======
 *                          `=---='
 *
 *==================================================
 *                  佛祖保佑        永无BUG
 *         佛曰:
 *                写字楼里写字间，写字间里程序员；
 *                程序人员写程序，又拿程序换酒钱。
 *                酒醒只在网上坐，酒醉还来网下眠；
 *                酒醉酒醒日复日，网上网下年复年。
 *                但愿老死电脑间，不愿鞠躬老板前；
 *                奔驰宝马贵者趣，公交自行程序员。
 *                别人笑我忒疯癫，我笑自己命太贱；
 *                不见满街漂亮妹，哪个归得程序员？
 *==================================================
 */

 
/**
 * 苦令营周期配置
 * @author  Don
 * @date    2019-05-28
 */

namespace App\Admin\Controllers\kly;

use App\Models\kly\kly_camp_student;
use App\Models\kly\Kly_term;
use App\Models\kly\Kly_camp;
use App\Models\kly\Squad;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use App\Admin\Extensions\ExcelExpoter;
use Maatwebsite\Excel\Facades\Excel;
use Encore\Admin\Show;
use Illuminate\Http\Request;
use DB;

class Kly_studentController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('学员');
            $content->description('管理');
            
            $content->body($this->grid()->render());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Kly_camp_student::class, function (Grid $grid) {
            $grid->model()->orderBy('squad','Asc');
            $grid->no('学号')->sortable();
            $grid->ch_name('中文名')->sortable();
            $grid->en_name('英文名')->sortable();
            $grid->sex('性别')->display(function($sex){
                if($this->sex=='1')
                {
                    return '男';
                }elseif($this->sex=='2')
                {
                    return '女';
                }
            })->sortable();
            $grid->squad('所在班级')->sortable();
            $grid->grade('年级')->display(function($grade){
                switch ($this->grade) {
                    case '1':
                        return '一年级';
                        break;
                    case '2':
                        return '二年级';
                        break;
                    case '3':
                        return '三年级';
                        break;
                    case '4':
                        return '四年级';
                        break;
                    case '5':
                        return '五年级';
                        break;
                    case '6':
                        return '六年级';
                        break;
                    case '7':
                        return '初一';
                        break;
                    case '8':
                        return '初二';
                        break;
                    case '9':
                        return '初三';
                        break;
                    case '10':
                        return '高一';
                        break;
                    case '11':
                        return '高二';
                        break;
                    case '12':
                        return '高三';
                        break;
                    default:
                        return 'N/A';
                        break;
                }
            })->sortable();
            $grid->enrollment_time('入学时间')->display(function($enrollment_time){
                return date('Y-m-d',strtotime($this->enrollment_time));
            })->sortable();
            $grid->big_camp('所在大营')->sortable();
            $grid->small_camp('所在小营')->sortable();
            $grid->camp_group('所在小组')->display(function($camp_group){
                if ($this->camp_group=='') {
                    return 'N/A';
                }else{
                    return $this->camp_group;
                }
            })->sortable();
            $grid->term_name('周期')->sortable();

            //禁用导出按钮
            $grid->disableExport();
/*            $filename="苦令营学生列表";
            $grid->exporter(new ExcelExpoter($grid,$filename));*/
            //禁用筛选按钮
            // $grid->disableFilter();
            $grid->disableActions();
            $grid->disableCreateButton();
            $grid->tools(function ($tools) { 
                //关闭批量删除 
                $tools->batch(function ($batch) { 
                    $batch->disableDelete(); 
                });
            });
            $grid->expandFilter();
             //筛选弹出框字段
            $grid->filter(function ($filter) {
                $filter->column(1/4, function ($filter) {
                    // 去掉默认的id过滤器
                    $filter->disableIdFilter();
                    $filter->equal('t_id','周期')->select(Kly_term::where('status','1')->pluck('name','id'));
                    $filter->like('en_name',trans('admin.en_name'));
                });
                $filter->column(1/4, function ($filter) {
                    $filter->equal('b_id', '大营')->select(Kly_camp::where('camp_type','1')->pluck('name','id'));
                    $filter->like('ch_name',trans('admin.ch_name'));
                });
                $filter->column(1/4, function ($filter) {
                    $filter->equal('s_id', '小营')->select(Kly_camp::where('camp_type','2')->pluck('name','id'));
                    $filter->like('squad',trans('admin.squad'));
                    
                });
                $filter->column(1/4, function ($filter) {
                    $filter->equal('g_id', '小组')->select(Kly_camp::where('camp_type','3')->pluck('name','id'));;
                });
            });
        });
    }
    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        
    }
}